package com.sh.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
    public static void main(String[] args) {
        try {
            //创建连接工厂
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("101.33.234.248");
            factory.setUsername("guest");
            factory.setPassword("guest");

            //创建连接
            Connection connection = factory.newConnection();

            //开启信道(传送消息的通道)
            Channel channel = connection.createChannel();

            //创建队列
            channel.queueDeclare("hello", false, false,false,null);
            //队列名
            String msg = "hello word";
            //发送
            channel.basicPublish("", "hello", null, msg.getBytes());

            System.out.println("发送成功");

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
